<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring MVC 控制器注解详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-gradient::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            bottom: -50%;
            left: -50%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            animation: pulse 4s ease-in-out infinite;
        }
        
        @keyframes pulse {
            0%, 100% { transform: scale(1); opacity: 0.5; }
            50% { transform: scale(1.1); opacity: 0.8; }
        }
        
        .card-hover {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
            position: relative;
        }
        
        .code-block::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 40px;
            background: #2d2d2d;
            display: flex;
            align-items: center;
            padding: 0 16px;
        }
        
        .code-content {
            padding: 60px 24px 24px;
            color: #d4d4d4;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 14px;
            line-height: 1.6;
            overflow-x: auto;
        }
        
        .annotation-tag {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 14px;
            font-weight: 500;
            display: inline-block;
            margin: 4px;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 8px;
            margin-top: -8px;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .comparison-table {
            background: white;
            border-radius: 16px;
            overflow: hidden;
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
        }
        
        .comparison-table th {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 16px;
            text-align: left;
            font-weight: 600;
        }
        
        .comparison-table td {
            padding: 16px;
            border-bottom: 1px solid #e5e7eb;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #ffeaa7 0%, #fab1a0 100%);
            border-radius: 12px;
            padding: 20px;
            margin: 20px 0;
            position: relative;
            overflow: hidden;
        }
        
        .highlight-box::before {
            content: '\f0eb';
            font-family: 'Font Awesome 6 Free';
            font-weight: 900;
            position: absolute;
            right: 20px;
            top: 50%;
            transform: translateY(-50%);
            font-size: 48px;
            opacity: 0.2;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 relative">
        <div class="container mx-auto px-6 relative z-10">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">
                    Spring MVC 控制器注解
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    深入理解 @Controller 与 @RestController 的区别与应用
                </p>
                <div class="flex justify-center space-x-4">
                    <span class="annotation-tag">
                        <i class="fas fa-code mr-2"></i>Spring MVC
                    </span>
                    <span class="annotation-tag">
                        <i class="fas fa-server mr-2"></i>RESTful API
                    </span>
                    <span class="annotation-tag">
                        <i class="fas fa-layer-group mr-2"></i>Web开发
                    </span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">在</span>Spring MVC框架中，控制器注解是构建Web应用程序的核心组件。<code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">@Controller</code>和<code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">@RestController</code>作为两个最重要的控制器注解，它们在处理HTTP请求和响应方面扮演着不同的角色。理解它们的区别对于构建高效的Spring应用至关重要。
            </p>
        </div>

        <!-- Visual Comparison Diagram -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-diagram-project mr-3 text-purple-600"></i>架构对比图
            </h2>
            <div class="mermaid">
                graph TB
                    subgraph "客户端请求"
                        A[HTTP Request]
                    end
                    
                    subgraph "@Controller 处理流程"
                        B[@Controller]
                        C[处理业务逻辑]
                        D[返回视图名称]
                        E[视图解析器]
                        F[渲染HTML页面]
                    end
                    
                    subgraph "@RestController 处理流程"
                        G[@RestController]
                        H[处理业务逻辑]
                        I[返回数据对象]
                        J[自动序列化为JSON/XML]
                    end
                    
                    A --> B
                    A --> G
                    B --> C --> D --> E --> F
                    G --> H --> I --> J
                    
                    style A fill:#667eea,stroke:#fff,color:#fff
                    style B fill:#764ba2,stroke:#fff,color:#fff
                    style G fill:#764ba2,stroke:#fff,color:#fff
                    style F fill:#48bb78,stroke:#fff,color:#fff
                    style J fill:#48bb78,stroke:#fff,color:#fff
            </div>
        </div>

        <!-- Controller Annotation Details -->
        <div class="grid md:grid-cols-2 gap-8 mb-12">
            <!-- @Controller Card -->
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="feature-icon">
                    <i class="fas fa-file-code"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4 text-gray-800">@Controller 注解</h3>
                <p class="text-gray-600 mb-6">
                    @Controller 用于标识一个类为Spring MVC的控制器组件，主要用于传统的MVC架构，返回视图页面。
                </p>
                
                <div class="highlight-box mb-6">
                    <h4 class="font-bold text-gray-800 mb-2">
                        <i class="fas fa-star mr-2"></i>核心特性
                    </h4>
                    <ul class="text-gray-700 space-y-2">
                        <li><i class="fas fa-check-circle text-green-500 mr-2"></i>配合视图解析器使用</li>
                        <li><i class="fas fa-check-circle text-green-500 mr-2"></i>返回视图名称或ModelAndView</li>
                        <li><i class="fas fa-check-circle text-green-500 mr-2"></i>适用于服务端渲染页面</li>
                    </ul>
                </div>
                
                <div class="code-block">
                    <div class="code-content">
<pre>@Controller
public class ExampleController {
    @RequestMapping("/example")
    public String handleRequest(Model model) {
        // 处理请求并返回视图
        model.addAttribute("message", "Hello Spring MVC!");
        return "view"; // 返回视图名称
    }
}</pre>
                    </div>
                </div>
            </div>

            <!-- @RestController Card -->
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <div class="feature-icon">
                    <i class="fas fa-code-branch"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4 text-gray-800">@RestController 注解</h3>
                <p class="text-gray-600 mb-6">
                    @RestController 是 @Controller 和 @ResponseBody 的组合，专门用于构建RESTful API。
                </p>
                
                <div class="highlight-box mb-6">
                    <h4 class="font-bold text-gray-800 mb-2">
                        <i class="fas fa-star mr-2"></i>核心特性
                    </h4>
                    <ul class="text-gray-700 space-y-2">
                        <li><i class="fas fa-check-circle text-green-500 mr-2"></i>自动序列化响应对象</li>
                        <li><i class="fas fa-check-circle text-green-500 mr-2"></i>返回JSON/XML数据</li>
                        <li><i class="fas fa-check-circle text-green-500 mr-2"></i>适用于前后端分离架构</li>
                    </ul>
                </div>
                
                <div class="code-block">
                    <div class="code-content">
<pre>@RestController
public class ExampleRestController {
    @RequestMapping("/api/example")
    public ExampleObject handleRequest() {
        // 生成并返回响应数据
        ExampleObject response = new ExampleObject();
        response.setStatus("success");
        return response; // 自动转换为JSON
    }
}</pre>
                    </div>
                </div>
            </div>
        </div>

        <!-- Comparison Table -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-balance-scale mr-3 text-purple-600"></i>详细对比
            </h2>
            <div class="overflow-x-auto">
                <table class="comparison-table w-full">
                    <thead>
                        <tr>
                            <th>特性</th>
                            <th>@Controller</th>
                            <th>@RestController</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td class="font-semibold">主要用途</td>
                            <td>传统Web应用，返回HTML视图</td>
                            <td>RESTful API，返回数据</td>
                        </tr>
                        <tr>
                            <td class="font-semibold">返回值处理</td>
                            <td>通过视图解析器处理</td>
                            <td>自动序列化为JSON/XML</td>
                        </tr>
                        <tr>
                            <td class="font-semibold">注解组合</td>
                            <td>单独使用@Controller</td>
                            <td>@Controller + @ResponseBody</td>
                        </tr>
                        <tr>
                            <td class="font-semibold">适用场景</td>
                            <td>服务端渲染、MVC架构</td>
                            <td>前后端分离、微服务</td>